package com.crm.jdy.controller.project;

import com.crm.jdy.common.dto.ProjectInfoDto;
import com.crm.jdy.common.dto.ProjectTaskInfoDto;
import com.crm.jdy.common.pojo.ProjectInfo;
import com.crm.jdy.common.pojo.ProjectTaskInfo;
import com.crm.jdy.common.utils.api.ResultVo;
import com.crm.jdy.common.utils.currentlimiting.RateLimit;
import com.crm.jdy.service.project.ProjectInfoService;
import com.crm.jdy.service.project.ProjectTaskInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.validation.constraints.NotNull;

/**
*
* <p>说明： 项目任务信息API接口层</P>
* @version: V1.0
* @author: kong
* @time    2021年4月9日
*
*/
@Api(tags = "projectTaskInfo", description ="项目任务信息")
@RestController
@RequestMapping("/projectTaskInfo")
public class ProjectTaskInfoController{

    @Reference(version = "${service.version}", check = false)
    ProjectTaskInfoService projectTaskInfoService;

    @RateLimit()
    @ApiOperation("项目任务信息")
    @PostMapping("/seleteProjectTaskInfo")
    public ResultVo seleteProjectTaskInfo(@RequestBody ProjectTaskInfoDto projectInfoDto){
        PageInfo<ProjectTaskInfo> list = projectTaskInfoService.seleteProjectTaskInfo(projectInfoDto);
        return  ResultVo.success(list);
    }

    @RateLimit()
    @ApiOperation("更新项目任务信息")
    @PostMapping("/updateProjectTaskInfo")
    public ResultVo updateProjectTaskInfo(@ApiParam(value = "projectInfo", required = true)
                                      @Validated @RequestBody ProjectTaskInfo projectInfo){
        boolean index = projectTaskInfoService.updateProjectTaskInfo(projectInfo);
        if(index){
            return  ResultVo.success();
        }
        return  ResultVo.failed();
    }

    @RateLimit()
    @ApiOperation("添加项目任务信息")
    @PostMapping("/addProjectTaskInfo")
    public ResultVo addProjectTaskInfo(@ApiParam(name = "projectInfo", required = false)
                                   @Validated @RequestBody ProjectTaskInfo projectInfo){
        boolean list  = projectTaskInfoService.addProjectTaskInfo(projectInfo);
        if(list){
            return ResultVo.success("添加成功");
        }
        return ResultVo.failed("添加失败，数据已存在");
    }

    @RateLimit()
    @ApiOperation("删除项目任务信息")
    @DeleteMapping("deleteProjectTaskInfo/{taskId}")
    public ResultVo deleteProjectInfo(@NotNull @ApiParam(name = "taskId", value = "taskId", required = true) @PathVariable String taskId){
        boolean b = projectTaskInfoService.removeProjectTaskInfo(taskId);
        if(b){
            return ResultVo.success();
        }
        return ResultVo.failed();
    }




}